/**
 * 
 */


import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.ServletException;

import org.apache.struts2.StrutsSpringTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.furschina.model.Channel;

/**
 * @author iday
 *
 */
public class ChannelActionTestCase extends StrutsSpringTestCase {

	/* (non-Javadoc)
	 * @see org.apache.struts2.StrutsSpringTestCase#getContextLocations()
	 */
	@Override
	protected String[] getContextLocations() {
		return new String[]{"classpath:spring-test.xml"};
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link com.furschina.struts2.portal.ChannelAction#create()}.
	 * @throws ServletException 
	 * @throws UnsupportedEncodingException 
	 */
	@SuppressWarnings("unchecked")
	@Test
	public void testCreate() throws UnsupportedEncodingException {
		request.setMethod("post");
		request.addParameter("list.label", new String[]{"测试一", "测试二"});
		try {
			executeAction("/portal/channel.xhtml");
		} catch (ServletException e) {
			//这里什么都不用做。
		}
		List<Channel> list = (List<Channel>) findValueAfterExecute("list");
		assertEquals(2, list.size());
	}
	
	@SuppressWarnings("unchecked")
	@Test
	public void testIndex() throws UnsupportedEncodingException, ServletException {
		request.setMethod("get");
		executeAction("/portal/channel.xhtml");
		List<Channel> list = (List<Channel>) findValueAfterExecute("list");
		assertEquals(2, list.size());
		
	}

}
